<template>
	<view class="Customer-page">
		<view class="Customer">
			<view class="user-img">
				<uv-image :src="infoData.avatar" width="72px" height="72px" shape="circle"></uv-image>
				<!-- <image src="/static/images/user-img.png" mode="aspectFill"></image> -->
			</view>
			<view class="Customer-name">
				{{infoData.nickName}}<text class="news">(新客户)</text>
			</view>
		</view>
		<view class="Customer-info">
			<view class="info-item">
				<view class="p">
					年龄：{{age || '未知'}}岁
				</view>
				<view class="p">
					消费次数：{{infoData.consumeNum || '0'}}次
				</view>
				<view class="p">
					喜欢服务项目：{{infoData.likeServiceName || '--'}}
				</view>
			</view>
			<view class="info-item">
				<view class="p">
					性别：{{infoData.sexName || '--'}}
				</view>
				<view class="p">
					手机号：{{infoData.phonenumber || '--'}}
				</view>
				<view class="p">
					最喜欢的技师：{{infoData.likeUserName || '--'}}号
				</view>
			</view>
		</view>
		<view class="link" @click="goto()">
			<text>服务记录列表</text>
			<uv-icon color="#666" name="arrow-right"></uv-icon>
		</view>
		<view class="tbody">
			<view class="customer-item">
				<view class="title">常用包厢号</view>
				<view class="cont">
				{{infoData.serveRoom || '--'}}
				</view>
			</view>
			<view class="customer-item">
				<view class="title">常用服务项目</view>
				<view class="cont">
					{{infoData.servicePage || '--'}}
				</view>
			</view>
			<view class="customer-item">
				<view class="title">常用技师</view>
				<view class="cont">
					{{infoData.jsUserName || '--'}}
				</view>
			</view>
			<view class="customer-item">
				<view class="title">常用茶水</view>
				<view class="cont">
					{{infoData.serveTea || '--'}}
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				appUserId: null,
				infoData: {},
				age:null,
				actions: [{
					name: '男',
					value: 0,
				}, {
					name: '女',
					value: 1,
				}, {
					name: '未知',
					value: 2,
				}, ],
			}
		},
		onLoad(option) {
			if(this.$store.state.isLoginType==1){
				this.appUserId = option.appUserId
			}else{
				this.appUserId = this.$store.state.userInfo.appUserId
			}
			
			this.getList();
		},
		methods: {
			async getList() {
				// 根据客户id查询详情
				// appUserId:this.appUserId
				const {
					code,
					data
				} = await this.muajax.getJsCustomerId({}, {
					urlRewrite: url => `${url}/${this.appUserId}`
				});
				this.infoData = data
				this.infoData.sexName = data.sex ? this.actions.filter(v => v.value == data.sex)[0].name : ''
				this.age=calculateAge(this.infoData.birthDate)
			},
			calculateAge(birthdate) {
				const birthDate = new Date(birthdate);
				const difference = Date.now() - birthDate.getTime();
				const age = new Date(difference);
				return Math.abs(age.getUTCFullYear() - 1970);
			},
			goto() {
				uni.navigateTo({
					url: '/technicianPages/myCustomer/serviceRecord?appUserId='+this.appUserId
				})
			}
		}
	}
</script>
<style scoped lang="less">
	page {
		background: #f1f1f1;
	}

	.Customer {
		padding: 30rpx 0px;
		border-bottom: 1px solid #f1f1f1;
		text-align: center;
		width: 100%;
		background: #fff;

		.user-img {
			// width: 120rpx;
			// height: 120rpx;
			border-radius: 50%;
			margin: 0px auto;
			display: flex;
			justify-content: center;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.Customer-name {
			color: #333333;
			margin-top: 15rpx;

			.news {
				color: #00c6c3;
				font-size: 24rpx;
			}
		}
	}

	.Customer-info {
		display: flex;
		width: 100%;
		background: #fff;

		.info-item {
			width: 50%;
			padding: 30rpx;
			box-sizing: border-box;
			color: #666666;
			line-height: 40rpx;

			&:nth-child(1) {
				border-right: 1px solid #f1f1f1;
			}
		}
	}

	.link {
		height: 90rpx;
		padding: 0px 80rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #999999;
		font-size: 32rpx;
		background: #fff;
		border-top: 1px solid #f1f1f1;

	}

	.tbody {
		background-color: #ffffff;
		border-radius: 20rpx;
		width: 690rpx;
		margin: 30rpx auto;

		.customer-item {
			padding: 20rpx 40rpx;
			box-sizing: border-box;

			.title {
				color: #00c6c3;
				font-size: 32rpx;
				box-sizing: border-box;
				text-align: center;
				margin-bottom: 20rpx;
			}

			.cont {
				min-height: 100rpx;
				background-color: #f1f1f1;
				border-radius: 10rpx;
				padding: 20rpx;
				box-sizing: border-box;
				color: #666666;
				font-size: 24rpx;
			}
		}
	}
</style>